export default {
  namespaced: true,
  state: {
    // 1. 用户令牌
    token: uni.getStorageSync('token') || '',
    // 2. 收货地址
    address: uni.getStorageSync('105-address') || {},
    // 3. 用户信息
    userinfo: uni.getStorageSync('105-userinfo') || {}
  },
  getters: {
    fullAddress(state) {
      const { provinceName, cityName, countyName, detailInfo } = state.address;
      return provinceName + cityName + countyName + detailInfo;
    },
  },
  mutations: {
    /**
     * 1. 设置地址
     * @param {*} state 
     * @param {*} address 
     */
    setAddress(state, address) {
      state.address = address
      uni.setStorageSync('105-address', address)
    },
    /**
     * 2. 更新用户的基本信息
     * @param {*} state 
     * @param {*} userinfo 
     */
    updateUserInfo(state, userinfo) {
      state.userinfo = userinfo
      // 持久化到本地缓存
      uni.setStorageSync('105-userinfo', state.userinfo)
    },
    /**
     * 3. 持久化存储token
     * @param {*} state 
     * @param {*} token 
     */
    setToken(state, token) {
      state.token = token || ''
      uni.setStorageSync('token', state.token)
    },
  },
  actions: {}
}